package net.lab1024.sa.admin.module.business.lcy.room.service;

import java.util.List;
import net.lab1024.sa.admin.module.business.lcy.room.dao.LcyRoomDao;
import net.lab1024.sa.admin.module.business.lcy.room.domain.entity.LcyRoomEntity;
import net.lab1024.sa.admin.module.business.lcy.room.domain.form.LcyRoomAddForm;
import net.lab1024.sa.admin.module.business.lcy.room.domain.form.LcyRoomQueryForm;
import net.lab1024.sa.admin.module.business.lcy.room.domain.form.LcyRoomUpdateForm;
import net.lab1024.sa.admin.module.business.lcy.room.domain.vo.LcyRoomVO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;

/**
 * 教室 Service
 *
 * @Author yangz
 * @Date 2025-10-31 16:14:07
 * @Copyright yangz
 */

@Service
public class LcyRoomService {

    @Resource
    private LcyRoomDao lcyRoomDao;

    /**
     * 分页查询
     */
    public PageResult<LcyRoomVO> queryPage(LcyRoomQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<LcyRoomVO> list = lcyRoomDao.queryPage(page, queryForm);
        return SmartPageUtil.convert2PageResult(page, list);
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(LcyRoomAddForm addForm) {
        LcyRoomEntity lcyRoomEntity = SmartBeanUtil.copy(addForm, LcyRoomEntity.class);
        lcyRoomDao.insert(lcyRoomEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     */
    public ResponseDTO<String> update(LcyRoomUpdateForm updateForm) {
        LcyRoomEntity lcyRoomEntity = SmartBeanUtil.copy(updateForm, LcyRoomEntity.class);
        lcyRoomDao.updateById(lcyRoomEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     */
    public ResponseDTO<String> batchDelete(List<Long> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        lcyRoomDao.deleteBatchIds(idList);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Long roomId) {
        if (null == roomId){
            return ResponseDTO.ok();
        }

        lcyRoomDao.deleteById(roomId);
        return ResponseDTO.ok();
    }
}
